_Pragma("once");

#include <string>
#include <map>
#include <iostream>

#include "CommandExecutor.h"
#include "LoopStatus.h"
#include "SingletonTemplate.h"
#include "CommandDispatcher.h"

class CommandDispatcher;

class JsonCommandParser {
    friend class SingletonTemplate<JsonCommandParser>;

public:

    /** Default destructor */
    ~JsonCommandParser();



    void onDownloadFile(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);


    void onExtendDeviceConfig(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);


    void onAcSwitchStatus(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void onVideoControl(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void lock(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void unlock(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void updateBackupPassword(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void onUploadOfflineSystemInfo(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void onExtendDeviceStatus(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void onForwardData(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void notImplemented(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result) {}


    std::string& buildAcSwitchStatusResponse(const std::string& switchMode, const std::string& loopSwitchStatus, std::string& result);

    std::string& buildAlertInfo(const std::string& alertType, std::string& result);

    using  CommandFunctionPointor = void (JsonCommandParser::*)(NetworkString& detailCmd, const NetworkString::size_type dataIndex, std::string& result);

    void parseCommand(NetworkString& data, NetworkString& result);


    CommandExecutor& mcommandExecutor = CommandExecutorSingleton::instance();

    /** Default constructor */
    JsonCommandParser();

protected:
    std::map<std::string_view, CommandFunctionPointor>  mcommandToFunction{
        {"downloadFile", &JsonCommandParser::onDownloadFile}
        ,{"extendDeviceConfig", &JsonCommandParser::onExtendDeviceConfig}
        ,{"acSwitchStatus", &JsonCommandParser::onAcSwitchStatus}
        ,{"videoControl", &JsonCommandParser::onVideoControl}
        ,{"lock", &JsonCommandParser::lock}
        ,{"unlock", &JsonCommandParser::unlock}
        ,{"updateBackupPassword", &JsonCommandParser::updateBackupPassword}
        ,{"uploadOfflineSystemInfo", &JsonCommandParser::onUploadOfflineSystemInfo}
        ,{"extendDeviceStatus", &JsonCommandParser::onExtendDeviceStatus}
        ,{"forwardData", &JsonCommandParser::onForwardData}
        ,{"notImplemented", &JsonCommandParser::notImplemented}
    };
};


using JsonCommandParserSingleton = class SingletonTemplate<JsonCommandParser>;

